/**
 * @author florian
 */
Ext.namespace('Ext.sql');

Ext.sql.TreeLoader = Ext.extend(Ext.tree.TreeLoader, {
    
    load : function(node, callback){
        if(this.clearOnLoad){
            while(node.firstChild){
                node.removeChild(node.firstChild);
            }
        }
        if(this.doPreload(node)){ 
            if(typeof callback == "function"){
                callback();
            }
        }
        var conn = Ext.data.SqlDB.getInstance();
        conn.open('picturemanagair.db');
        
        this.store = new Ext.sql.SQLiteStore({
           dbFile: 'picturemanagair.db',
           key: 'id',
           fields: [
                {name: 'id',    type:'integer'},
                {name: 'name', type:'string'}
            ]
        });
    },

    requestData: function(node, callback) {
        console.log(arguments);
        if(this.fireEvent("beforeload", this, node, callback) !== false){
            this.store.proxy.load({
                args: [node]
            }, this.reader, this.handleQuery, this);
        }
        else{
            if(typeof callback == "function"){
                callback();
            }
        }
    }
});


